/*
 * p2486.cpp
 *
 *  Created on: 2013-7-24
 *      Author: zy
 */
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;
int dp[110][210][2], value[110];
vector<int> son[110];
int n, m;
void dfs(int u, int pa)
{
	for (int i = 0; i <= m; i++)
		dp[u][i][0] = dp[u][i][1] = value[u];
	for (int i = 0; i < son[u].size(); i++)
	{
		int v = son[u][i];
		if (v == pa)
			continue;
		dfs(v,u);
		for(int j=m;j>=1;j--)
			for(int k=0;k<=j-1;k++)
			{
				if(j-k-2>=0)
				{
					dp[u][j][0]=max(dp[u][j][0],dp[u][j-k-2][0]+dp[v][k][0]);
					dp[u][j][1]=max(dp[u][j][1],dp[u][j-k-2][1]+dp[v][k][0]);
				}
				dp[u][j][1]=max(dp[u][j][1],dp[u][j-k-1][0]+dp[v][k][1]);
			}
	}
}
int main()
{
	while (scanf("%d%d", &n, &m) != EOF)
	{
		for (int i = 1; i <= n; i++)
		{
			scanf("%d", &value[i]);
			son[i].clear();
		}
		for (int i = 1; i < n; i++)
		{
			int x, y;
			scanf("%d%d", &x, &y);
			son[x].push_back(y);
			son[y].push_back(x);
		}
		dfs(1, 0);
		printf("%d\n", dp[1][m][1]);
	}
	return 0;
}
